#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>
#include "Game.h"
#include "ScriptedEntity.h"
#include "InfoBox.h"
//EVERTHING IS 64X64
//Version is 0.09

using namespace std;
int main()
{
    Game& gam = Game::Instance();
    gam.init("wee", 800, 600); //Window title, width, height




    Player me;


    //Method 1 of loading tiles, with definitions. Allows you to quickly create tiles. For now factory functions are better,
    // but there will soon be more properties.
    TileDef tdef;
    tdef.SetVal("solid", true);
    tdef.SetVal("x", 0);
    tdef.SetVal("y", 0);
    tdef.SetString("image", "tile.png");

    gam.addtile(tdef);

    tdef.SetVal("y", 1);
    tdef.SetVal("solid", false);

    gam.addtile(tdef);

    tdef.SetVal("x", 0);
    tdef.SetVal("y", 2);

    gam.addtile(tdef);


    //Load player

    PlayerDef playdef;
    playdef.SetVal("x", 1);
    playdef.SetVal("y", 1);
    playdef.SetVal("rotation", 0);
    playdef.SetString("image", "player.png");

    me.init(playdef); //Definition way

    gam.SetPlayer(me); //Assign player to game

    //Add a little test entity
    Def edef;
    edef.SetVal("x", 0);
    edef.SetVal("y", 2);
    edef.SetVal("solid", true);
    edef.SetString("image", "player.png");
    gam.addent(edef);


    //Set up an info box for the player
    InfoBox player(gam.GetPlayer());

    //Lets run a small script
    ScriptManager& inst = ScriptManager::Instance();
    inst.init();
    inst.ExecScript("testent.lua");
    //inst.ExecScript("1.lua");
    //inst.OpenTable("asdf");
    //inst.CallTableFunc("Cool");
    //inst.CloseTable();
    //inst.BeginCall("x");
    //inst.AddNumber(500);
    //inst.Call();
    //inst.Close();


    //test a scripted entity
    Def sdef;
    sdef.SetString("entname", "prop_static");
    ScriptedEntity sent;
    sent.init(sdef);
    gam.addent(&sent);

    while(gam.run())
    {
        //Update and draw the game.
        gam.update();
        gam.draw();
        player.draw();
    }
    inst.Close();
    return 0;
}
